/**
 * Created by Jan-Home on 2016/11/15 0015.
 */

function runTests(tests) {
	_.forEach(tests, function (test) {
		if (typeof test.method === 'function' && test.values && _.isArray(test.values) && test.values.length) {
			var bind = test.object || null;
			var method = test.method;
			QUnit.test(test.name, function (assert) {
				_.forEach(test.values, function (values) {
					var then = values[0];
					if (!_.isArray(then))
						then = [then];
					then = method.apply(bind, then);
					var excepted = values[1];
					assert.equal(then, excepted);
				});
			});
		}
	});
}

QUnit.module("ke-url/path", function (hooks) {

	var tests = [
		{
			name: 'isAbsolute',
			method: keUrl.isAbsolute,
			values: [
				["../abc/def", false],
				["/abc/def", true],
				["abc/def", false],
				["", false],
				["/", true],
				["./abc/def", false]
			]
		},
		{
			name: 'normalize',
			method: keUrl.normalize,
			values: [
				["bbb/ccc.html", 'bbb/ccc.html'],
				["/./aaa/../bbb/ccc", '/bbb/ccc'],
				["/../aaa/./bbb/ccc", '/aaa/bbb/ccc'],
				["/../a/./b/c/d/../e/f/../", '/a/b/c/e/'],
				["../a/./b/c/d", '../a/b/c/d'],
				["./a/./b/c/d", 'a/b/c/d']
			]
		},
		{
			name: 'resolve',
			method: keUrl.resolve,
			values: [
				[['/aa', 'bb'], '/aa/bb'],
				[['/aa', '/bb'], '/bb'],
				[['/aa', '../bb'], '/bb'],
				[['/aa', '../bb', './cc'], '/bb/cc'],
				[['/aa', '../bb', '../cc'], '/cc']
			]
		}
	];

	runTests(tests);
});

